﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Gammar.Digger.BLL;
using Gammar.Digger.SystemFramework;
using Gammar.Digger.Entity;
using Gammar.Digger.BLL.Common;
using System.Collections.Generic;
public partial class plugin_List : System.Web.UI.Page
{
    private string _website_id
    {
        set { ViewState["v_siteid"] = value; }

        get { return ViewState["v_siteid"] == null ? string.Empty : ViewState["v_siteid"].ToString(); }
    }

    private string _sort
    {
        set { ViewState["v_sort"] = value; }

        get { return ViewState["v_sort"] == null ? string.Empty : ViewState["v_sort"].ToString(); }
    }
    private string _where = string.Empty;
  
   // private const string CS_webSites="cache_website";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            _website_id = Request.QueryString["site_id"];
            _sort = Request.QueryString["sort"];
            BindData(_sort);

        }
    }

    private void BindData(string sort)
    {
        if (!string.IsNullOrEmpty(_website_id))
        {
            _where = "site_id=" + _website_id;
        }

        SortList<digger_pluginEntity> plugins = PluginManagement.GetList(_where);

        string lastSort = string.Empty;

        if (!string.IsNullOrEmpty(_sort))
        {
            ddlsort.Items.FindByValue(_sort).Selected = true;
        }
        switch (sort)
        {
            case "0":
                plugins.Sort("site_id", true);
                break;

            case "1":
                plugins.Sort("category_id", true);
                break;
            default:
                break;
        }
        rptPlugin.DataSource = plugins;
        rptPlugin.DataBind();
    }

    protected string GetWebSiteName(int siteid)
    {

        SortList<web_siteEntity> sites = WebSiteManagement.GetAllWebSite();

        foreach (web_siteEntity site in sites)
        {
            if (site.site_id==siteid)
            {
                return site.name;
            }
        }
        return string.Empty;
    }

    protected string GetCategoryName(string category_id)
    {
        Dictionary<string,string> dicts= WebSiteManagement.GetAllWebSiteCategory();

        return dicts[category_id] == null ? string.Empty : dicts[category_id];
    }

    protected void ddlsort_SelectedIndexChanged(object sender, EventArgs e)
    {
        //BindData(ddlsort.SelectedValue);
        _sort=ddlsort.SelectedValue;
        Response.Redirect("List.aspx?site_id=" + _website_id + "&sort=" + _sort);

    }

    protected string FormatIsValid(object str)
    {
        if (str.ToString().ToLower().Equals("true"))
        {
            return "<font color='Blue'>True</font>";
        }
        else
        {
            return "<font color='Red'>False</font>";
        }
    }
}
